<template>
  <view @click="changeSwitch">
    <switch disabled :color="color" :checked="checked" />
  </view>
</template>
<script setup lang="ts">
/**
 * 引用此组件时，添加v-model同步切换checked，不加则单向变更checked
 */
const props = withDefaults(
  defineProps<{
    checked: boolean
    color: string
  }>(),
  {
    color: '#108ee9',
  }
)
const emit = defineEmits<{
  (e: 'change', checked: boolean): void
  (e: 'update:checked', checked: boolean): void
}>()
function changeSwitch(e: any) {
  emit('change', !props.checked)
  emit('update:checked', !props.checked)
}
</script>
<style lang="less"></style>
